package com.asuka.controller.admin;

import com.asuka.dto.OrderSearchDTO;
import com.asuka.entity.Orders;
import com.asuka.result.PageResult;
import com.asuka.result.Result;
import com.asuka.service.OrderService;
import com.asuka.vo.OrderStatisticsVO;
import com.asuka.vo.OrderVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/admin/order")
@RestController("adminOrderController")
@Slf4j
public class OrderController {

    @Autowired
    private OrderService orderService;


    @GetMapping("/conditionSearch")
    public Result<PageResult> search(OrderSearchDTO orderSearchDTO){
        PageResult page = orderService.search(orderSearchDTO);

        return Result.success(page);
    }


    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> statistics(){

        OrderStatisticsVO vo = orderService.statistics();

        return Result.success(vo);
    }

    @GetMapping("/details/{id}")
    public Result<OrderVO> selectOrderDetails(@PathVariable Long id){

        OrderVO orderVO = orderService.details(id);

        return Result.success(orderVO);
    }

    //接单
    @PutMapping("/confirm")
    public Result confirm(@RequestBody Orders order){
        orderService.confirm(order);
        return Result.success();
    }


    //拒单
    @PutMapping("/rejection")
    public Result rejection(@RequestBody Orders order){
        orderService.rejection(order);
        return Result.success();
    }

    //取消订单
    @PutMapping("/cancel")
    public Result cancel(@RequestBody Orders order){
        orderService.adminCancel(order);
        return Result.success();
    }

    //派送
    @PutMapping("/delivery/{id}")
    public Result delivery(@PathVariable Long id){
        orderService.delivery(id);
        return Result.success();
    }


    //完成订单
    @PutMapping("/complete/{id}")
    public Result complete(@PathVariable Long id){
        orderService.complete(id);

        return Result.success();
    }


}
